<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <!-- <title>导航管理 - {{.SITE_NAME}}</title> -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">

    <title>导航管理 - {{.SITE_NAME}}</title>

    <link href="/static/bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <link href="/static/font-awesome/css/font-awesome.min.css" rel="stylesheet">

    <link href="/static/css/main.css?version={{$.Version}}" rel="stylesheet">
    <script src="/static/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="/static/respond.js/1.4.2/respond.min.js"></script>
    <link rel="stylesheet" href="/static/css/toast.css">
</head>

<body>
    <div class="manual-reader">
        {{template "widgets/header.html" .}}
        <div class="{{if $.IsWideScreen}}container-fluid container-widescreen{{else}}container{{end}} manual-body">
            <div class="row">
                <div class="page-left">
                    {{template "manager/menu.html" .}}
                </div>
                <div class="page-right">
                    <div class="m-box">
                        <div class="box-head">
                            <strong class="box-title">导航管理</strong>
                            <button type="button" class="btn btn-success btn-sm pull-right" onclick="editNav(0)">
                                <i class="fa fa-plus"></i> 添加导航
                            </button>
                        </div>
                        <div class="box-body">
                            <table class="table table-hover">
                                <thead>
                                    <tr>
                                        <th>ID</th>
                                        <th>名称</th>
                                        <th>链接</th>
                                        <th>图标</th>
                                        <th>打开方式</th>
                                        <th>排序</th>
                                        <th>状态</th>
                                        <th>操作</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    {{range .Lists}}
                                    <tr>
                                        <td>{{.Id}}</td>
                                        <td>{{.Name}}</td>
                                        <td>{{.Url}}</td>
                                        <td>
                                            {{if .Icon}}
                                                {{if navOr (hasPrefix .Icon "/") (hasPrefix .Icon "http://") (hasPrefix .Icon "https://")}}
                                                    <img src="{{.Icon}}" class="icon-img" alt="{{.Name}}" title="{{.Icon}}">
                                                {{else}}
                                                    <i class="{{.Icon}}" {{if .Color}}style="color:{{.Color}}"{{end}} title="{{.Icon}}"></i>
                                                {{end}}
                                            {{end}}
                                            <span class="nav-icon-text">{{.Icon}}</span>
                                        </td>
                                        <td>{{if eq .Target "_blank"}}新窗口{{else}}当前窗口{{end}}</td>
                                        <td>{{.Sort}}</td>
                                        <td>
                                            {{if eq .Status 0}}
                                                <span class="text-success">启用</span>
                                            {{else}}
                                                <span class="text-danger">禁用</span>
                                            {{end}}
                                        </td>
                                        <td>
                                            <button class="btn btn-sm btn-primary"
                                                onclick="editNav({{.Id}})">编辑</button>
                                            <button class="btn btn-sm btn-danger"
                                                onclick="deleteNav({{.Id}})">删除</button>
                                        </td>
                                    </tr>
                                    {{end}}
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script src="/static/jquery/1.12.4/jquery.min.js"></script>
    <script src="/static/bootstrap/js/bootstrap.min.js"></script>
    <script src="/static/layer/layer.js"></script>
    <script src="/static/js/jquery.form.js"></script>
    <script src="/static/js/main.js"></script>

    <script>
        function editNav(id) {
            layer.open({
                type: 2,
                title: id > 0 ? '编辑导航' : '添加导航',
                shadeClose: true,
                shade: 0.8,
                area: ['580px', '520px'],
                content: '/manager/navs/edit?id=' + id
            });
        }

        function deleteNav(id) {
            layer.confirm('确定要删除该导航吗?', { icon: 3 }, function (index) {
                $.post('/manager/navs/delete', { id: id }, function (res) {
                    if (res.errcode === 0) {
                        layer.msg('删除成功');
                        setTimeout(function () {
                            window.location.reload();
                        }, 1000);
                    } else {
                        layer.msg(res.message);
                    }
                });
                layer.close(index);
            });
        }
    </script>
</body>

</html>